<?php
class CourseFee extends Controller {
	var $msg = '';
	
	function CourseFee()
	{
		parent::Controller();
	}
	
	function index()
	{
	 	if ($this->session->userdata('logged_in') != TRUE)
	    {
	        redirect('login/index');
	    }
	    $this->load->model('CourseModel');
	    $data['courseList'] = $this->CourseModel->getAll();
	    
	    $this->load->model('filemanagementmodel');
	    $data['howto_payment'] = $this->filemanagementmodel->getByPostion('howto_payment');
	    
		$this->load->view('header');
		$this->load->view('course-fee-form', $data);
		if($this->msg != null && count($this->msg) > 0)
			$msg = array('msg' => $this->msg);
		else
			$msg = null;
		$this->load->view('footer', $msg);
	}
	
	function save()
	{
		if ($this->session->userdata('logged_in') != TRUE)
	    {
	        redirect('login/index');
	    }
	    $this->load->model('CourseModel');
	    $courseID = $this->input->post('courseID');
	    $level = $this->input->post('level');
	    $studentFee = $this->input->post('studentFee');
	    $graduatedFee = $this->input->post('graduatedFee');
	    
	    for($i = 0; $i < count($courseID); $i++) {
	    	$data = array();
	    	$data['course_id'] = $courseID[$i];
    		$data['level'] = $level[$i];
    		$data['fee_student'] = $studentFee[$i];
    		$data['fee_graduate'] = $graduatedFee[$i];
    		$this->CourseModel->update($data);
	    }
	    
	    $this->load->model('filemanagementmodel');
	    $d['position'] = 'howto_payment';
	    $d['longd'] = $this->input->post('txtHowtoPay');
		$this->filemanagementmodel->update($d);
	    
	    $this->msg = "บันทึกข้อมูลเรียบร้อย";
	    $this->index();
	}
}
?>